package com.by.wx.service.impl;

import java.sql.Timestamp;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.by.common.vo.PhoneRoomResult;
import com.by.wx.dao.WxinDao;
import com.by.wx.entity.PhoneMember;
import com.by.wx.entity.SysEquipmentOperate;
import com.by.wx.entity.SysRoomMemberResult;
import com.by.wx.service.WxinService;

@Service
public class WxinServiceImpl implements WxinService {

	public static Log log = LogFactory.getLog(WxinServiceImpl.class);

	@Autowired
	private WxinDao wxinDao;

	@Override
	public List<PhoneMember> findPrivilegeByOpenidVerifyToSkipHref(String openid) {
		// no verify openid==null
		return wxinDao.findPrivilegeByOpenidVerifyToSkipHref(openid);
	}

	@Override
	public List<PhoneRoomResult> findCheckRoomLineById(Integer vipId) {
		return wxinDao.findCheckRoomLineById(vipId);
	}

	@Override
	public int deletePhoMemberCodedByOpenid(String openid) {
		// no verify openid==null
		return wxinDao.deletePhoMemberCodedByOpenid(openid);
	}

	@Override
	public int updatePhoCodeByOpenid(String code, Timestamp lastCodeTime, String openid) {
		// no verify openid==null
		return wxinDao.updatePhoCodeByOpenid(code, lastCodeTime, openid);
	}

	@Override
	public List<PhoneRoomResult> findCheckRoomLineByPhone(String phone) {
		if (StringUtils.isEmpty(phone))
			throw new RuntimeException("手机号码不能为空");
		return wxinDao.findCheckRoomLineByPhone(phone);
	}

	@Override
	public List<SysEquipmentOperate> findOperationByEquipmentId(Integer deviceId) {
		return wxinDao.findOperationByEquipmentId(deviceId);
	}

	@Override
	public List<SysRoomMemberResult> verifyRoomControlPage(String renterId, String roomId, String timestamp,
			String sign) {
		Session session = SecurityUtils.getSubject().getSession();
		String nativeSign = (String) session.getAttribute("sign");
		String rid = (String) session.getAttribute("room_id");
		String vid = (String) session.getAttribute("renter_id");
		String times = (String) session.getAttribute("timestamp");
		// System.out.println(nativeSign);
		// System.out.println(rid);
		// System.out.println(vid);
		// System.out.println(times);
		return null;
	}

	@Override
	public int updateSessionTimeSignByOpenid(Timestamp timestamp, String sign, String openid) {
		int row = wxinDao.updateSessionTimeSignByOpenid(timestamp, sign, openid);
		return row;
	}

}
